﻿package com.shuqi.common;

import android.text.TextUtils;

public class ROT13 {
    public static String rot13(String src) {
        if (TextUtils.isEmpty(src)) {
            return "";
        }

        StringBuilder sb = new StringBuilder(src);
        char s;
        for (int i = 0; i < sb.length(); i++) {
            s = sb.charAt(i);
            if ('A' <= s && s <= 'Z') {
                s = (char) (s + 13);
                if (s > 'Z') {
                    s = (char) ((s % 'Z') + 'A' - 1);
                }
            } else if ('a' <= s && s <= 'z') {
                s = (char) (s + 13);
                if (s > 'z') {
                    s = (char) ((s % 'z') + 'a' - 1);
                }
            }
            sb.setCharAt(i, s);
        }
        return sb.toString();
    }
}
